<template>
    <view>
        <view class="cu-bar bg-white solid-bottom">
            <view class="action">
                <text class='cuIcon-title text-blue'></text>
                无课表查询
            </view>
        </view>
        <view class="margin-left margin-right">
            <view class="cu-form-group margin-top-xs">

                <view class="title">周数</view>
                <picker @change="PickerChange" :value="weekIndex" :range="weeks">
                    <view class="picker">
                        {{weekIndex < 0 ? '请选择一个周数':week}}
                    </view>
                </picker>
            </view>
            <view class="cu-form-group">
                <view class="title">星期</view>
                <picker @change="dateChange" :value="selectedDateIndex" range-key="date" :range="dateList">
                    <view class="picker">
                        {{selectedDateIndex < 0 ? '请选择一个星期':selectedDate}}
                    </view>
                </picker>
                <!--        <picker mode="multiSelector" @change="MultiChange" @columnchange="MultiColumnChange" :value="multiIndex" :range="multiArray">-->
                <!--          <view class="picker">-->
                <!--            {{multiArray[0][multiIndex[0]]}}，{{multiArray[1][multiIndex[1]]}}，{{multiArray[2][multiIndex[2]]}}-->
                <!--          </view>-->
                <!--        </picker>-->
            </view>
            <view class="cu-form-group">
                <view class="title">部门</view>
                <picker @change="departmentChange" :value="selectedDepartmentIndex" range-key="department_name" :range="departmentList">
                    <view class="picker">
                        {{selectedDepartmentIndex < 0 ? '请选择一个部门':selectedDepartmentName}}
                    </view>
                </picker>
            </view>
            <view class="cu-form-group">
                <view class="title">开始节次</view>
                <picker @change="beginChange" :value="beginIndex" :range="beginList">
                    <view class="picker">
                        {{beginIndex < 0 ? '请选择开始节次':begin}}
                    </view>
                </picker>
            </view>
            <view class="cu-form-group">
                <view class="title">结束节次</view>
                <picker @change="endChange" :value="endIndex" :range="endList">
                    <view class="picker">
                        {{endIndex < 0 ? '请选择结束节次':end}}
                    </view>
                </picker>
            </view>
            <view class="flex flex-wrap justify-between align-center bg-white btn_center">
                <button @tap="Search" class="cu-btn round lg equry_btn">查询</button>
            </view>

        </view>
    </view>

</template>

<script>

const app = getApp();


export default {
    data() {
        return {
            weeks:[],
            week:'1',
            weekIndex:-1,

            departmentList:[{
                department_id:-1,
                department_name:""
            }],
            selectedDepartmentId:-1,
            selectedDepartmentName:"",
            selectedDepartmentIndex:-1,

            dateList:[{
                date_id:1,
                date:"星期一"
            },{
                date_id:2,
                date:"星期二"
            },{
                date_id:3,
                date:"星期三"
            },{
                date_id:4,
                date:"星期四"
            },{
                date_id:5,
                date:"星期五"
            },{
                date_id:6,
                date:"星期六"
            },{
                date_id:7,
                date:"星期天"
            }],
            selectedDateIndex:-1,
            selectedDate:"",
            dateId:-1,

            beginList:[],
            begin:"1",
            beginIndex:-1,

            endList:[],
            end:"1",
            endIndex:-1

        }
    },
    onLoad(e){
        this.id = e.id;
        let tempWeeks = [];
        let tempBegin=[];
        let tempEnd=[];
        for (let i = 1;i<=20;i++){
            tempWeeks.push(i);
        }
        this.weeks = tempWeeks;

        for (let i = 1;i<=12;i++){
            tempBegin.push(i);
        }
        this.beginList = tempEnd;

        for (let i = 1;i<=12;i++){
            tempEnd.push(i);
        }
        this.endList = tempEnd;

        this.getDepartment();
    },
    onBackPress(e){
        uni.reLaunch({
            url: '../../pages/association/detail/detail?id=' + this.id
        });
    },
    methods: {
        PickerChange(e){
            this.weekIndex = e.detail.value;
            this.week = this.weeks[this.weekIndex];
        },
        departmentChange(e){
            this.selectedDepartmentIndex = e.detail.value;
            this.selectedDepartmentName = this.departmentList[this.selectedDepartmentIndex].department_name;
            this.selectedDepartmentId = this.departmentList[this.selectedDepartmentIndex].department_id;

        },
        dateChange(e){
            this.selectedDateIndex=e.detail.value;
            this.dateId=this.dateList[this.selectedDateIndex].date_id;
            this.selectedDate=this.dateList[this.selectedDateIndex].date;

            console.log(this.selectedDateIndex)
            console.log(this.selectedDate)

            // this.dataIndex=e.detail.value;
            // this.data=this.dataList[this.dataIndex];
        },
        beginChange(e){
            this.beginIndex=e.detail.value;
            this.begin=this.beginList[this.beginIndex];

            let tempEnd=[];
            for(let i = this.begin;i<=12;i++){
                tempEnd.push(i);
            }
            this.endList = tempEnd;

        },
        endChange(e){
            this.endIndex=e.detail.value;
            this.end=this.endList[this.endIndex];

            let tempStart = [];
            for(let i = 1;i<=this.end;i++){
                tempStart.push(i);
            }
            this.beginList = tempStart;

        },
        getDepartment(){
            this.$myFunction.getData(app.globalData.ApiUrl + 'api/Android/getAssociationDepartmentList',{
                SafeCode: uni.getStorageSync('SafeCode'),
                association_id:this.id
            }).then((res)=>{
                this.departmentList = res.data;
            })
        },
        Search(){

            let tempUrl = 'result?'+
                'association_id='+this.id+
                '&department_id='+this.selectedDepartmentId+
                '&week='+this.week+
                '&day='+this.dateId+
                '&from_section='+this.begin+
                '&to_section='+this.end;

            uni.navigateTo({
                url: tempUrl
            });
        }


    }
}
</script>

<style scoped>
.top {
    line-height: normal;
    text-align: center;
    background-color: white;
}

.equry_btn {
    background-color: #409eff;
    margin: 20px auto;
    color: white;
}

</style>